// ----------------------------------------------------------------------
//  Jack McCaffery
//  11-30-2014
// ----------------------------------------------------------------------

#include "topicModel/generalParameters.H"
#include "topicModel/fixedParameters.H"

#include <QtTest/QtTest>

#include <iostream>
using namespace std;


/// \brief test class for basicData class
class GeneralParameters_test : public QObject
{

Q_OBJECT

private slots:

	/// \brief Initialize data for testing
	void initTestCase ();

	/// \brief Test general parameters functionality
	void testGradient ();

	/// \brief Cleanup after testing
	void cleanupTestCase ();

private:
	/// \brief Test parameters
	GeneralParameters<double> g;

	/// \brief Test parameters
	GeneralParameters<double> h;

	/// \brief Gradient to apply
	FixedParameters<double> gradient;
};

void GeneralParameters_test::initTestCase()
{
	g.getData ().resize (2, 3);

	g[0][0] = 5;
	g[0][1] = 10;
	g[0][2] = -20;
	g[1][0] = -1;
	g[1][1] = 0;
	g[1][2] = 1;

	h.getData ().resize (2, 3);

	h[0][0] = 1;
	h[0][1] = 2.7;
	h[0][2] = 3;
	h[1][0] = 3;
	h[1][1] = 2.7;
	h[1][2] = 1.1;

	gradient.getData ().resize (2, 3);

	gradient[0][0] = 1;
	gradient[0][1] = 2;
	gradient[0][2] = 3;
	gradient[1][0] = -10;
	gradient[1][1] = -7;
	gradient[1][2] = 20;
}

void GeneralParameters_test::testGradient()
{
	GeneralParameters<double> test;

	test = g;
	test.applyGradient (gradient, 0);

	QVERIFY (test == g);

	test = g;
	test.applyGradient (gradient, 2);

	QVERIFY (qFuzzyCompare (test[0][0], 7));
	QVERIFY (qFuzzyCompare (test[0][1], 14));
	QVERIFY (qFuzzyCompare (test[0][2], -14));
	QVERIFY (qFuzzyCompare (test[1][0], -21));
	QVERIFY (qFuzzyCompare (test[1][1], -14));
	QVERIFY (qFuzzyCompare (test[1][2], 41));

	test = h;
	test.applyGradient (gradient, -1.5);

	QVERIFY (qFuzzyCompare (test[0][0], -0.5));
	QVERIFY (qFuzzyCompare (test[0][1], -0.3));
	QVERIFY (qFuzzyCompare (test[0][2], -1.5));
	QVERIFY (qFuzzyCompare (test[1][0], 18));
	QVERIFY (qFuzzyCompare (test[1][1], 13.2));
	QVERIFY (qFuzzyCompare (test[1][2], -28.9));
}

void GeneralParameters_test::cleanupTestCase ()
{

}


QTEST_MAIN (GeneralParameters_test)
#include "generalParameters_test.moc"
